﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BingVis.Common;

namespace BingVis.GoogleTransit
{
    public class CSVLine : ICSVLine
    {
        Dictionary<string, string> _fields;
        Dictionary<int, string> _columns;

        public CSVLine(Dictionary<string, string> fields)
        {
            _fields = fields;
            _columns = new Dictionary<int, string>();
            
            int i = 0;            
            foreach (var field in _fields.Values)
            {
                _columns[i] = field;
                ++i;
            }
        }

        #region ICSVLine Members

        public string this[string fieldName]
        {
            get { return _fields.ContainsKey(fieldName) ? _fields[fieldName] : ""; }
        }

        public string this[int column]
        {
            get { return _columns.ContainsKey(column) ? _columns[column] : ""; }
        }

        public IEnumerable<string> Values
        {
            get 
            { 
                foreach (var key in _columns.Keys.OrderBy(x => x)) 
                    yield return _columns[key]; 
            }
        }

        #endregion
    }
}
